<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<%@include file="/WEB-INF/pages/include/prelude.jspf"%>
<%@include file="/WEB-INF/pages/include/common.jspf"%>
<link href="<c:url value='/static/css/memberInfo.css' />" type="text/css" rel="stylesheet"/>
<title>新增常用联系人</title>
<script type="text/javascript" src="<c:url value='/static/js/validate.js' />"></script>
<script type="text/javascript">
$(function(){
	var title = ${update_flag =='0'};
	if(title){
		$("#pagetitle").html('修改常用联系人');
	}else{
		$("#pagetitle").html('新增常用联系人');
	}
});

/**
 * 表单验证
 */
function submitForm(){
	
	if(!IsNull('familyName', '姓')){
		return false;
	}

	if(!IsNull('firstName', '名')){
		return false;
	}
	if(!IsNull('email', '邮箱地址')){
		return false;
	}
	if(!IsNull('mobile', '手机号码')){
		return false;
	}
	
	var email = $("#email").val();
	if(!testEmail(email)){
		return false;
	}
	
	var mobile = $("#mobile").val();
	if(!validatemobile(mobile)){
		return false;
	}
	$("#form").submit();
}

/*邮箱验证*/
function testEmail(str){  
	var reg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
	if(reg.test(str)){ 
		return true;
	}else{
		alert("请输入正确Email地址！");
		return false;
	}
}

/**
 * 手机号码验证
 */
function validatemobile(mobile)
{  
    if(mobile.length!=11)
    {
        alert('请输入有效的手机号码！');
        return false;
    }
    var myreg = /^1[0-9]{10}$/;
    if(!myreg.test(mobile))
    {
        alert('请输入有效的手机号码！');
        return false;
    }
    return true;
}

</script>
</head>
<body>
<div  data-role="page">
	<%@include file="/WEB-INF/pages/include/header.jsp"%>
	<div data-role="content">
		<form id="form" action="<c:url value='/member/addGuestInfo.do'/>" method="post" data-ajax="false" >
				<input type="hidden" name="searchId" value="${searchId }"  />
				<input type="hidden" name="index" value="${index }"  />
				<input type="hidden" name="count" value="${count }"  />
				<input type="hidden" name="customerIds" value="${customerIds }"  />
				<input type="hidden" id="guestId" name="guestId" value="${guestId }"  />
				<input type="hidden" name="adultCount" value="${adultCount }"  />
				<input type="hidden" id="childCount" name="childCount" value="${childCount }"  />
			<div class="m_item">
				<div class="m_title">添加联系人信息</div>
				<ul>
					<li><div class="i_label"><span class="xh">*</span>姓：</div>
					<input value="${guest==null? '':guest.familyName}" data-role="none" id="familyName" name="familyName" type="text" class="txt" /><div class="clear"></div></li>
					<li><div class="i_label"><span class="xh">*</span>名：</div>
					<input data-role="none" value="${guest==null? '':guest.firstName}" id="firstName" name="firstName" type="text" class="txt" /><div class="clear"></div></li>
					<li><div class="i_label"><span class="xh">*</span>邮件地址：</div>
					<input data-role="none" value="${guest==null? '':guest.email}" id="email" name="email" type="email" class="txt" /><div class="clear"></div></li>
					<li><div class="i_label"><span class="xh">*</span>手机号码：</div>
					<input data-role="none" id="mobile" value="${guest==null? '':guest.mobile}" onkeyup="value=this.value.replace(/\D+/g,'')" name="mobile" type="text" class="txt" /><div class="clear"></div></li>
				</ul>
			</div>
			<br />
			<div>
				<c:choose>
					<c:when test="${update_flag =='0'}">
						<input type="hidden" value="${guest.id }" name="guestId" />
						<input type="hidden" value="0" name="update_flag" />
						<button class="btn" onclick="submitForm();" data-theme="a" type="button">修改</button>
					</c:when>
					<c:otherwise>
						<button class="btn" onclick="submitForm();" data-theme="a" type="button">添加</button>
					</c:otherwise>
				</c:choose>
			</div>
		</form>
	</div>
	<div>
		<c:if test="${!empty errorMeg }">
			<c:forEach items="${errorMeg }" var="error">
				${error.key }:${error.value }<br/>
			</c:forEach>
		</c:if>
	</div>
</div>
</body>
</html>